/*
 *  Graphics.h
 *  c_Render
 *
 *  Created by liao peterson on 3/16/10.
 *  Copyright 2010 uestc. All rights reserved.
 *
 */
#ifndef GRAPHICS_H__
#define GRAPHICS_H__

#include"Macros.h"
#include "Mathutilis.h"
#include "DataStructures.h"
#include "Physics.h"
#include "GameMeshes.h"
#include "Scene.h"
#include "Audio.h"
#include "Fonts.h"

enum _RenderType{
	MODEL,			//3D Model
	TEXTURE			//2D Texture for UI
};

class RenderObject
{
public:
// Static Handles
	//static GLint m_u_mvpHandle;
	//static GLint m2w_Handle;
// Instance Buffers
	GLuint vboid;		// Vertex Buffer Object
	GLuint nboid;		// Normal Buffer
	GLuint tcoboid;		// Texture coordinate buffer
	GLuint textureid;		// Texture buffer
	GLint TextureEnabled;
	
	_RenderType type;
	
	RenderObject(){
		TextureEnabled = 1;
	}
	
	//virtual void InitTexture();
	
	// when calling this method, you have to make sure the Texture Parameter is right!
	void InitTexture(GLuint texid);
	//virtual void InitTexture(GLchar*filename);
	
	virtual void render();
};

class RenderModel :public RenderObject
{
public:
	Mesh			  *	MeshRef;
	physicsIntegrator * PhysicRef;
	GLint				PhysicsEnabled;
	
	RenderModel();
	RenderModel(Mesh*mTarget,physicsIntegrator*pTarget);
	
	void InitTexture();
	//void InitTexture(GLuint texid);
	void InitTexture(GLchar*filename);
	
	virtual void render(Matrix4x4*World2Camera,GLint m2w_Handle,GLint m_u_mvpHandle);
};

class RenderTexture :public RenderObject
{
public:
	// Start position for TextureDrawing in Clip Coord
	GLfloat startX,startY;
	GLfloat endX,endY;
	// Position for texture in tex coord
	GLfloat coXs,coYs;
	GLfloat coXe,coYe;
	
	GLint texWidth,texHeight;
	GLubyte*textureData;
	
	//RenderTexture();
	RenderTexture(GLfloat startX=-1.0f,GLfloat startY=-1.0f,GLfloat endX=1.0f,GLfloat endY=1.0f);
	RenderTexture(GLchar*filename,GLfloat startX=-1.0f,GLfloat startY=0.5f,GLfloat endX=1.0f,GLfloat endY=0.9f,
									GLfloat coXs=0.0f,GLfloat coYs=0.0f,GLfloat coXe=1.0f,GLfloat coYe=1.0f);
	//RenderTexture(GLchar*filename,GLfloat startX=-1.0f,GLfloat startY=-1.0f,
	//								GLfloat endX=1.0f,GLfloat endY=1.0f);
	// -1.0f,0.5f,1.0f,0.9f
	//void InitTexture();
	//void InitTexture(GLuint texid);
	void InitTexture(GLchar*filename);
	
	virtual void render();
	virtual void render(GLfloat startX,GLfloat startY,GLfloat endX,GLfloat endY,
						GLfloat coXs=0.0f,GLfloat coYs=0.0f,GLfloat coXe=1.0f,GLfloat coYe=1.0f);
	
	// Use the original size
	void render(GLfloat startX,GLfloat startY,Font ch,GLfloat scale = 1.0f);
	void render(GLfloat startX,GLfloat startY,GLfloat endX,GLfloat endY,Font ch);
};



#endif